package com.Relaxing.Cup;

import com.Relaxing.Cup.Graphics.*;

/**
 * Created by mathias on 6/09/13.
 */
public class Ship {

    public static final int MAX_ACEL = 2;
    public static final int INITIAL_LIVES = 2;
    private double posX = 0;
    private double posY = 0;
    private Cabine cabine;
    private int fire;
    private int type;
    private Shield shield;
    private double shield_level = 0;
    private int fire_level = 0;
    private int movingVertical = 0;
    private int movingHorizontal = 0;
    private int live;
    private int liveBar;
    private static final double MAX_SHIELD = 6;
    private final int MAX_LIVE;

    Ship(double x, double y, int type, int level) {
        posX = x;
        posY = y;
        this.type = type;
        this.live = level; //Only for enemies.
        this.MAX_LIVE = level;
        createShip();
    }

    /**
     * @return the posX
     */
    public double getPosX() {
        return posX;
    }

    /**
     * @param posX the posX to set
     */
    public void setPosX(double posX) {
        this.posX = posX;
    }

    /**
     * @return the posY
     */
    public double getPosY() {
        return posY;
    }

    /**
     * @param posY the posY to set
     */
    public void setPosY(double posY) {
        this.posY = posY;
    }


    /**
     * @return the cabine
     */
    public Cabine getCabine() {
        return this.cabine;
    }

    /**
     * @param cabin the cabine to set
     */
    public void setCabine(Cabine cabin) {
        this.cabine = cabin;
    }

    /**
     * @return the fire
     */
    public int getFire() {
        return fire;
    }

    /**
     * @param fire the fire to set
     */
    public void setFire(int fire) {
        this.fire = fire;
    }

    public void move() {
        if (this.type == 1) {
            this.posX = this.posX - 1;
        }
        this.createShip();
    }

    private void createShip() {

        if (this.type == 1) {

            //Shape
            cabine = new Cabine();
            //Shields

            //LiveBar

            //Fire


        } else {
            /*this.shape = new Polygon();
            this.posX = this.posX + this.movingHorizontal;
            this.posY = this.posY + this.movingVertical;
            this.shape.getPoints().addAll(new Double[]{
                    this.getPosX() - 8, this.getPosY() - 4,
                    this.getPosX(), this.getPosY() - 4,
                    this.getPosX() + 10, this.getPosY() - 15,
                    this.getPosX() + 8, this.getPosY() - 4,
                    this.getPosX() + 20, this.getPosY() - 4,
                    this.getPosX() + 30, this.getPosY(),
                    this.getPosX() + 20, this.getPosY() + 4,
                    this.getPosX() + 8, this.getPosY() + 4,
                    this.getPosX() + 10, this.getPosY() + 15,
                    this.getPosX(), this.getPosY() + 4,
                    this.getPosX() - 8, this.getPosY() + 4,
                    this.getPosX() - 8, this.getPosY() - 4,});
            Stop[] stops = new Stop[]{new Stop(0, Color.RED), new Stop(1, Color.WHITE), new Stop(1, Color.BLACK)};
            LinearGradient lg = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stops);
            this.shape.setFill(lg);


            this.shield = new Circle(this.getPosX() + 7, this.getPosY(), 26, Color.TRANSPARENT);
            this.shield.setStroke(Color.BLUE);
            this.shield.setStrokeWidth(this.shield_level);


            this.fire = new Polygon();
            this.fire.getPoints().addAll(new Double[]{
                    this.getPosX() - 10, this.getPosY() - 4,
                    this.getPosX() - 20 - diff, this.getPosY() - 4,
                    this.getPosX() - 12, this.getPosY() - 2,
                    this.getPosX() - 20 - diff, this.getPosY(),
                    this.getPosX() - 12, this.getPosY() + 2,
                    this.getPosX() - 20 - diff, this.getPosY() + 4,
                    this.getPosX() - 10, this.getPosY() + 4,});
            Stop[] stops2 = new Stop[]{new Stop(0, Color.RED), new Stop(1, Color.YELLOW), new Stop(1, Color.RED)};
            LinearGradient lg2 = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops2);
            this.fire.setFill(lg2);*/
        }
    }

    public boolean checkPossition(double x, double y) {
        boolean val = false;
        /*if (this.type == 1) {
            if (this.shape.contains(x, y)) {
                val = true;
            }
            //System.out.println("CHECKING x(-10,+20):" + (this.getPosX()) + "      --- y:" + (this.getPosY() + 6 + NewRType.SHOT_SIZE / 2));
        } else {
            if (this.shape.contains(x, y)) {
                val = true;
            }
        }*/
        return val;
    }

    public Shield getShield() {
        return this.shield;
    }

    /**
     * @return the movingVertical
     */
    public int getMovingVertical() {
        return movingVertical;
    }

    /**
     * @param movingVertical the movingVertical to set
     */
    public void setMovingVertical(int movingVertical) {
        this.movingVertical = movingVertical;
    }

    /**
     * @return the movingHorizontal
     */
    public int getMovingHorizontal() {
        return movingHorizontal;
    }

    /**
     * @param movingHorizontal the movingHorizontal to set
     */
    public void setMovingHorizontal(int movingHorizontal) {
        this.movingHorizontal = movingHorizontal;
    }

    /**
     * @return the fire_level
     */
    public int getFire_level() {
        return fire_level;
    }

    /**
     * @param fire_level the fire_level to set
     */
    public void setFire_level(int fire_level) {

        this.fire_level = fire_level;

    }

    /**
     * @return the shield_level
     */
    public double getShield_level() {
        return shield_level;
    }

    /**
     * @param shield_level the shield_level to set
     */
    public void setShield_level(double shield_level) {
        if (this.shield_level < MAX_SHIELD) {
            this.shield_level = shield_level;
        }
    }

    /**
     * @return the live
     */
    public int getLive() {
        return live;
    }

    /**
     * @param live the live to set
     */
    public void setLive(int live) {
        this.live = live;
    }

    /**
     * @return the liveBar
     */
    public int getLiveBar() {
        return liveBar;
    }

    /**
     * @param liveBar the liveBar to set
     */
    public void setLiveBar(int liveBar) {
        this.liveBar = liveBar;
    }
}
